<template>
	<div>
        <setHeader :title="headerTitle" settext="保存" @done="UpdateEmail()" :back-fn="goback"></setHeader>
        <div class="pagecontent">
		    <mt-field placeholder="请输入邮箱" v-model="update_arr.email"></mt-field>
        </div>
	</div>
</template>
<script>
import setHeader from '../public/setHeader.vue';
import { MessageBox } from 'mint-ui';
import qs from 'qs';

export default {

	data() {
      return {
        username: '',
        userInfo:'',
        headerTitle:'电子邮件',
        update_arr:{
            email:'',
            access_token:'',
        },
      };
    },
    components: {
		setHeader,
    },
    created() {
        let that = this;
        that.userInfo = window.localStorage.getItem('userInfo');
        that.userInfo = JSON.parse(that.userInfo);
        that.update_arr.email = that.userInfo.usermail;
    },
    mounted() {
    	// let that = this;
    	// var a = Promise.resolve(this.getUserInfo())
		// a.then(
		// 	function (result) { 
        //     console.log(result);
		// 	that.userInfo = result;
        //     that.update_arr.email = result.usermail;
		// })
      // console.log(that.userInfo);
    },
    methods:{
        UpdateEmail() { 
            let that = this;
            if (!/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(that.update_arr.email)) {
                that.$openTips({
                    text: "邮箱格式错误",
                    time:2000
                });
                return;
            }
            let access_token = window.localStorage.getItem('access_token');
            that.update_arr.access_token = access_token;
            if(that.update_arr.email){ 
                that.$post(that.$path+'/index.php/api/Email',that.update_arr).then((response) => { 
                    if(response.code == 200){ 
                        that.$router.push({path:'/userUpdate'});
                    }
                })
            }
            that.$emit('UpdateEmaildone');
        },
        goback() {
            this.$emit('done');
        }
    },
    props: ['done', 'UpdateEmaildone']
}

</script>

<style >
.el-long-create-button{
	margin-top:50px;
}
</style>